﻿cmake_minimum_required(VERSION 3.16)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
project(ftpTestApp)

message(STATUS "ftpTestApp  compiler: ${CMAKE_CXX_COMPILER}")
message(STATUS "ftpTestApp PROJECT_SOURCE_DIR: ${PROJECT_SOURCE_DIR}")
# message(STATUS "ftpTestApp CMAKE_CURRENT_SOURCE_DIR: ${CMAKE_CURRENT_SOURCE_DIR}")

if (MSVC)
    add_compile_options(/EHsc)
    add_compile_options(/utf-8)
endif()

# 可执行程序源文件
file(GLOB SRC_FILES
    ${PROJECT_SOURCE_DIR}/src/*.cpp
)

set(PRO_ROOT ${PROJECT_SOURCE_DIR}/../..)


if (MSVC)
    set(CURL_STATIC_LIB "${PRO_ROOT}/thirdParty/Lib/VS/win64/${CMAKE_BUILD_TYPE}/libcurl.lib")
    # set(SPDLOG_STATIC_LIB "${PRO_ROOT}/thirdParty/Lib/VS/win64/${CMAKE_BUILD_TYPE}/libspdlogStatic.lib")
elseif (MINGW OR GCC)# MinGW 或其他 GCC 兼容编译器
    set(CURL_STATIC_LIB "${PRO_ROOT}/thirdParty/Lib/MinGW/win64/${CMAKE_BUILD_TYPE}/libcurl.a")
    set(SPDLOG_STATIC_LIB "${PRO_ROOT}/thirdParty/Lib/MinGW/win64/${CMAKE_BUILD_TYPE}/libspdlogStatic.a")
elseif (UNIX AND NOT APPLE)# Linux / macOS
    # 假设你的库放在 thirdParty/Lib/Linux/x86_64/release 目录下
    set(CURL_STATIC_LIB "${PRO_ROOT}/thirdParty/Lib/Linux/${CMAKE_BUILD_TYPE}/libcurl.a")
    set(SPDLOG_STATIC_LIB "${PRO_ROOT}/thirdParty/Lib/Linux/${CMAKE_BUILD_TYPE}/libspdlogStatic.a")
endif()


# 包含头文件路径（优先从 library 取）
include_directories(
    ${PRO_ROOT}/include/curl
    ${PRO_ROOT}/test/ftpTest/include
    ${PROJECT_SOURCE_DIR}/include
)

# target_include_directories(ftpTestApp PRIVATE
#     ${CMAKE_CURRENT_SOURCE_DIR}/include
#     ${PROJECT_SOURCE_DIR}/thirdParty/curl/include/
# )

# 生成可执行程序
add_executable(ftpTestApp ${SRC_FILES})
# target_compile_definitions(ftpTestApp PRIVATE CSVLIB_EXPORTS)
# target_compile_definitions(ftpTestApp PRIVATE CURL_STATICLIB)
target_compile_definitions(ftpTestApp
    PRIVATE 
    CSVLIB_EXPORTS
    CURL_STATICLIB
)

set(WINDOWS_LIBS "" CACHE STRING "Windows specific libraries")
if(WIN32)
    # set(WINDOWS_LIBS "ws2_32 crypt32 bcrypt" CACHE STRING "Windows specific libraries" FORCE)ws2_32 crypt32 bcrypt
    set(WINDOWS_LIBS ws2_32 crypt32 bcrypt)
endif()

set(UNIX_LIBS "" CACHE STRING "UNIX specific libraries")

if(UNIX AND NOT APPLE)
    # Linux 下需要的库，包含 nghttp2
    set(UNIX_LIBS ssl crypto z pthread nghttp2 brotlidec brotlicommon) 

    foreach(lib ${UNIX_LIBS})
        find_library(LIB_${lib}_PATH NAMES ${lib})
        if(LIB_${lib}_PATH)
            list(APPEND UNIX_LIBS_FOUND ${LIB_${lib}_PATH})
        else()
            message(FATAL_ERROR "Cannot find library: ${lib}")
        endif()
    endforeach()
endif()

target_link_libraries(ftpTestApp PRIVATE
    ${CURL_STATIC_LIB}
    ${UNIX_LIBS_FOUND}
    ${SPDLOG_STATIC_LIB}
    ${CSV_LIBRARY}
    ${WINDOWS_LIBS}
)

# 可执行文件输出路径
set_target_properties(ftpTestApp PROPERTIES
    RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/Bin
)
